package com;

import com.alibaba.fastjson.JSONObject;
import com.b2.json.AIpojo.AiResponse;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class lx {

    private String post(String postURL,String name,String age) throws Exception {
        PostMethod postMethod = new PostMethod(postURL);
        postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
        //参数设置，需要注意的就是里边不能传NULL，要传空字符串
        NameValuePair[] data = {
                new NameValuePair("image", name),
                new NameValuePair("age", age)
        };
        postMethod.setRequestBody(data);
        org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
        httpClient.executeMethod(postMethod);
        String result = postMethod.getResponseBodyAsString();
        System.out.println(result.toString());
        return result;

    }

    public static void main(String[] args) {
        try {
            String post = new lx().post("http://47.108.185.179:5001/fine",
                    "https://qzkt-kc.oss-cn-hangzhou.aliyuncs.com/wechat/image/1715826985781109.png", "4"
            );
            char[] chars = post.toCharArray();
            for (int i = 0; i <chars.length ; i++) {
                if (chars[i]=='O'){
                    if (chars[i+1]>='0'&&chars[i+1]<='9'){
                        chars[i]='0';
                    }
                }
            }
            AiResponse aiResponse = JSONObject.parseObject(new String(chars), AiResponse.class);
            System.out.println(aiResponse);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
